﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SEO.Business;
using SEO.Entity;
using System.Data;

/// <summary>
/// 关键字操作
/// </summary>
public partial class EditKeywords : AdminPage
{
    /// <summary>
    /// ID
    /// </summary>
    protected int nID;


    protected void Page_Load(object sender, EventArgs e)
    {
        int.TryParse(Common.GetQueryValue("id", 0), out nID);

        if (!Page.IsPostBack)
        {
            InitSort();
            //页面数据初始化
            InitData();
        }
    }

    /// <summary>
    /// 权限控制
    /// </summary>
    /// <returns></returns>
    public override long GetNeededFeatures()
    {
        return AdminFEATURE.KeywordsList;
    }

    protected void InitSort()
    {
        DataTable dtSort = new BisSort().GetList();
        ddlSort.Items.Clear();
        ddlSort.Items.Add(new ListItem("请选择分类", "0"));
        foreach (DataRow drSort in dtSort.Rows)
        {
            ddlSort.Items.Add(new ListItem(drSort["Name"].ToString(), drSort["ID"].ToString()));
        }
        dtSort.Dispose();
    }

    /// <summary>
    /// 数据初始化
    /// </summary>
    protected void InitData()
    {
        Keywords Info = new BisKeywords().Get(nID);
        if (Info != null)
        {
            txtName.Text = Info.Name;
            ddlSort.SelectedValue = Info.SortID.ToString();
            txtScale.Text = Info.Scale.ToString();
        }
    }

    /// <summary>
    /// 提交操作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Keywords Info = new Keywords();
        Info.Name = txtName.Text.Trim();
        Info.SortID = Convert.ToInt32(ddlSort.SelectedValue);
        Info.Scale = Convert.ToDouble(txtScale.Text.Trim());
        BisKeywords bisInfo = new BisKeywords();
        Info.ID = nID;
        if (bisInfo.CheckKeywords(nID, Info.Name))
        {
            Until.Alert("关键字已经存在！");
            return;
        }
        else
        {
            bool bResult = bisInfo.Update(Info);
            //结果处理
            if (bResult)
            {
                Until.AlertJS("提交成功！", "ResetPage();");
            }
            else
            {
                Until.Alert("提交失败！");
            }
        }
    }
}